package container;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Description of the weapon trait.
 * 
 * @author Marcus
 */
@XmlRootElement
public class WeaponTraitDescription implements Comparable<WeaponTraitDescription>{

	private String traitName;

	private String traitCode;

	private boolean ratedTrait;

	private String ratingFormula;
	
	private String description;

	/**
	 * Returns the formula how the rating for this Trait is calculated.
	 * 
	 * @return
	 */
	@XmlElement(name = "Rating", required = true)
	public String getRatingFormula() {
		return this.ratingFormula;
	}

	/**
	 * Sets the formula how this rating is calculated.
	 * 
	 * @param rating
	 */
	public void setRatingFormula(String rating) {
		this.ratingFormula = rating;
	}

	/**
	 * @return the traitName
	 */
	@XmlAttribute(name = "Name", required = true)
	public String getTraitName() {
		return this.traitName;
	}

	/**
	 * @param name
	 *            the traitName to set
	 */
	public void setTraitName(String name) {
		this.traitName = name;
	}

	/**
	 * @return the code
	 */
	@XmlAttribute(name = "Code", required = true)
	public String getTraitCode() {
		return this.traitCode;
	}

	/**
	 * @param code
	 *            the code to set
	 */
	public void setTraitCode(String code) {
		this.traitCode = code;
	}

	/**
	 * @return the ratedTrait
	 */
	@XmlAttribute(name = "Rated", required = true)
	public boolean isRatedTrait() {
		return this.ratedTrait;
	}

	/**
	 * @param setRatedTrait
	 *            the ratedTrait to set
	 */
	public void setRatedTrait(boolean setRatedTrait) {
		this.ratedTrait = setRatedTrait;
	}

	/**
	 * @return the description
	 */
	@XmlElement (name = "Description")
	public String getDescription() {
		return this.description;
	}

	/**
	 * @param setDescription
	 *            the description to set
	 */
	public void setDescription(String setDescription) {
		this.description = setDescription;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((this.traitCode == null) ? 0 : this.traitCode.hashCode());
		result = prime * result
				+ ((this.traitName == null) ? 0 : this.traitName.hashCode());
		return result;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		WeaponTraitDescription other = (WeaponTraitDescription) obj;
		if (this.traitCode == null) {
			if (other.traitCode != null)
				return false;
		} else if (!this.traitCode.equals(other.traitCode))
			return false;
		if (this.traitName == null) {
			if (other.traitName != null)
				return false;
		} else if (!this.traitName.equals(other.traitName))
			return false;
		return true;
	}

	@Override
	public int compareTo(WeaponTraitDescription o) {
		return getTraitName().compareTo(o.getTraitName());
	}
}
